<template>
  <div>
    <h1>当前求和为：{{ sum }}</h1>
    <h1>放大十倍的和为：{{ bigSum }}</h1>
    <h3>我在{{ school }}，学习{{ subject }}</h3>
    <select v-model.number="number">
      <option value="1">1</option>
      <option value="2">2</option>
      <option value="3">3</option>
    </select>
    <button @click="increment(number)">+</button>
    <button @click="decrement(number)">-</button>
    <button @click="incrementOdd(number)">当前求和为奇数再加</button>
    <button @click="incrementWait(number)">等一等再加</button>
  </div>
</template>

<script>
//只能从指定对象中取出
import { mapState, mapGetters, mapMutations, mapActions } from "vuex";

export default {
  name: "Count",
  data() {
    return {
      number: 1,
    };
  },
  computed: {
    // //借助mapState生成计算属性：sum、school、subject（对象写法）
    // ...mapState({ he: "sum", xuexiao: "school", xueke: "subject" }),

    //借助mapState生成计算属性：sum、school、subject（数组写法）
    ...mapState(["sum", "school", "subject"]),

    // bigSum() {
    //   return this.$store.getters.bigSum;
    // },

    //借助mapGetters生成计算属性：bigSum（对象写法）
    // ...mapGetters({ bigSum: "bigSum" }),

    //借助mapGetters生成计算属性：bigSum（数组写法）
    ...mapGetters(["bigSum"]),
  },
  methods: {
    // increment() {
    //   this.$store.commit("JIA", this.number);
    // },
    // decrement() {
    //   this.$store.commit("JIAN", this.number);
    // },

    //借助mapMutations生成：increment、decrement（对象形式）
    ...mapMutations({ increment: "JIA", decrement: "JIAN" }),

    // //靠mapMutations生成：JIA、JIAN（对象形式）
    // ...mapMutations(["JIA", "JIAN"]),

    /* &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& */

    // incrementOdd() {
    //   this.$store.dispatch("jiaOdd", this.number);
    // },
    // incrementWait() {
    //   this.$store.dispatch("jiaWait", this.number);
    // },

    //靠mapActions生成：incrementOdd、incrementWait（对象形式）
    ...mapActions({ incrementOdd: "jiaOdd", incrementWait: "jiaWait" }),

    // //靠mapActions生成：incrementOdd、incrementWait（数组形式）
    // ...mapActions(["jiaOdd", "jiaWait"]),
  },
};
</script>

<style lang="css">
button {
  margin-left: 5px;
}
</style>